﻿using System;

public class Thumbnail
{
    private int thumbnailWidth;
    private int thumbnailHeight;
    private int boxSize;
    private System.Drawing.Image changeableImage;
    public Thumbnail(int boxSize, System.Drawing.Image changeableImage)
	{
        this.boxSize = boxSize;
        this.changeableImage = changeableImage;
        this.thumbnailWidth = WidthCorrection();
        this.thumbnailHeight = HeightCorrection();
	}
    public System.Drawing.Image Picture
    {
        get
        {
            return changeableImage.GetThumbnailImage(thumbnailWidth, thumbnailHeight, null, IntPtr.Zero); ;
        }
    }
    private int WidthCorrection()
    {
        if (changeableImage.Height < changeableImage.Width)
            return (int)(((double)changeableImage.Width / changeableImage.Height) * boxSize);
        else
            return boxSize;        
    }
    private int HeightCorrection()
    {
        if (changeableImage.Height < changeableImage.Width)
            return boxSize;
        else
            return (int)((double)changeableImage.Height / changeableImage.Width * boxSize);
    }
}
